<template>
  <div>
<h2>用户查看投资列表</h2>
投资名称:<input type="text" v-model="state.name">
<input type="button" value="查询" @click="show" class="btn btn-success">
<table class="table table-bordered">
  <tr>
    <td>投资id</td>
    <td>投资名称</td>
    <td>投资金额</td>
  </tr>
  <tr v-for="item in list" :key="item.FIU_Id">
    <td>{{ item.FIU_Id }}</td>
    <td>{{ item.FIU_Name }}</td>
    <td>{{ item.FIU_Money }}</td>
  </tr>
</table>
共{{ totalpage }}页
共{{ totalcount }}条
当前第{{ state.pageindex }}/{{ totalpage }}页
<input type="button" value="首页" @click="page('home')">
<input type="button" value="上一页" @click="page('prev')">
<input type="button" value="下一页" @click="page('next')">
<input type="button" value="尾页" @click="page('end')">
<input type="text" v-model="page1">
<input type="button" value="跳转" @click="page(page1)">
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRouter} from 'vue-router'
const router=useRouter()

const data:any=reactive({
  list:[],
  state:{
    name:'',
    pageindex:1,
    pagesize:2,
  },
  totalpage:'',
  totalcount:'',
  page1:''
})

let {list,state,totalpage,totalcount,page1} =toRefs(data)

onMounted(()=>{
  show()
})

const show=()=>{
  axios({
    url:'/api/Finance/GetFinanceList',
    method:'get',
    params:state.value
  }).then(res=>{
    console.log(res);
    list.value=res.data.data
    totalpage.value=res.data.totalpage
    totalcount.value=res.data.totalcount
  }).catch(err=>{
    console.log(err);
  })
}


const page=(str:any)=>{
  switch(str){
    case 'home':
      state.value.pageindex=1
      break
    case 'prev':
      if(state.value.pageindex==1){
        alert("已经是第一页了");
        return
      }
      state.value.pageindex--
      break
    case 'next':
      if(state.value.pageindex==totalpage.value){
        alert("已经是最后一页了");
        return
      }
      state.value.pageindex++
      break
    case 'end':
      state.value.pageindex=totalpage.value
      break
    case str:
      if(isNaN(str)){
        alert("请输入数字")
        return
      }
      if(str>totalpage.value){
        alert("超出总页数")
        return
      }
      state.value.pageindex=str
      break
    default:
      break
  }
  show()
}

</script>

<style scoped>

</style>